package qdu.edu.com.fushanf4.service.sort.twosort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import qdu.edu.com.fushanf4.utils.UtilConstants;

import java.io.IOException;

public class SortByTextAndThenByIntWritableMapper extends Mapper<LongWritable, Text, TextAndIntWritableBean, IntWritable> {
    private final TextAndIntWritableBean keyOut = new TextAndIntWritableBean();
    private final IntWritable valueOut = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] keyValue = line.split(UtilConstants.RegexOfString.HORIZONTAL_TABULATION);
        keyOut.set(keyValue[0], keyValue[1]);
        valueOut.set(Integer.parseInt(keyValue[1]));
        context.write(keyOut, valueOut);
    }
}
